//
//  CompanyViewController.m
//  zhixinApp
//
//  Created by zhiguanzhl on 2017/12/13.
//  Copyright © 2017年 zhiguanzhl. All rights reserved.
//

#import "CompanyViewController.h"
#import "MyTableViewCell.h"
#import "SelectMemberViewController.h"

@interface CompanyViewController ()
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong)UIImage *image0;
@property (nonatomic, strong)NSMutableArray *models;
@end

@implementation CompanyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"创建群组";
    self.tableView.tableFooterView = [[UIView alloc] init];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
        return [DataCenter shareInstence].companyList.count;
   
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return  64;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    MyTableViewCell *tableCell = [MyTableViewCell cellWithTableView:tableView];
        
        NSArray *companyModelArr = [DataCenter shareInstence].companyList;
        CompanyModel *model = companyModelArr[indexPath.row];
        tableCell.imageName.image = self.image0;
        tableCell.title.text = model.name;
        tableCell.countLable.text = model.employeeCount;
    
    return tableCell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSArray *companyModelArr = [DataCenter shareInstence].companyList;
    CompanyModel *model = companyModelArr[indexPath.row];
    SelectMemberViewController *selectVC = [[SelectMemberViewController alloc] init];
    selectVC.companyId = model.companyId;
#warning 改
//    保证数组这个对象是同一个就行了
//    ---------------------------------------
    selectVC.numModel.models = self.models;
    selectVC.block = ^(NSMutableArray *models) {
        self.models = models;
    };
//    ---------------------------------------
    if (self.conversationId) {
       //拉人
        selectVC.conversationId = self.conversationId;
        //把群组里的人全部传给了选择的人用来做标记
        selectVC.occupanys = self.occupanys;
    }else{
        //创建群组
        selectVC.isCreat = YES;
    }
   
    [self.navigationController pushViewController:selectVC animated:YES];
    
}
- (UIImage *)image0{
    if(!_image0){
        _image0 = [UIImage imageNamed:@"xiaoxi_logo"];
    }
    return _image0;
}

- (NSMutableArray *)models{
    if (!_models) {
        _models = [NSMutableArray array];
    }
    return _models;
}
@end
